package com.erp.gather.controller;

import com.erp.gather.domain.bo.ErpCollectProductSkuBo;
import com.ruoyi.gather.api.domain.vo.ErpCollectProductSkuVo;
import com.erp.gather.service.IErpCollectProductSkuService;
import com.ruoyi.common.core.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.core.web.oldPage.TableDataInfo;
import com.ruoyi.gather.api.domain.ErpCollectProductSku;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 采集商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
 *
 * @author erp
 * @date 2023-03-07
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/gather/collectProductSku")
public class ErpCollectProductSkuController extends BaseController {

    private final IErpCollectProductSkuService iErpCollectProductSkuService;

    /**
     * 根据skuCode获取采集sku信息
     */
    @GetMapping("/getSkuInfoBySkuCode/{skuCode}")
    ErpCollectProductSku getSkuInfoBySkuCode(@PathVariable("skuCode") String skuCode) {
        return iErpCollectProductSkuService.getSkuInfoBySkuCode(skuCode);
    }

    /**
     * 查询采集商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）列表
     */
    @GetMapping("/list")
    public TableDataInfo<ErpCollectProductSkuVo> list(ErpCollectProductSkuBo bo, PageQuery pageQuery) {
        return iErpCollectProductSkuService.queryPageList(bo, pageQuery);
    }


    /**
     * 获取采集商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<ErpCollectProductSkuVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iErpCollectProductSkuService.queryById(id));
    }

    /**
     * 新增采集商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     */
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpCollectProductSkuBo bo) {
        return toAjax(iErpCollectProductSkuService.insertByBo(bo));
    }

    /**
     * 修改采集商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     */
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpCollectProductSkuBo bo) {
        return toAjax(iErpCollectProductSkuService.updateByBo(bo));
    }

    /**
     * 删除采集商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）
     *
     * @param ids 主键串
     */
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iErpCollectProductSkuService.deleteWithValidByIds(Arrays.asList(ids), true));
    }


    @PostMapping("/getCollectProductSkuInfo")
    public R<Object> getCollectProductSkuInfo(@RequestBody ErpCollectProductSku erpCollectProductSkuSel){
        return iErpCollectProductSkuService.getCollectProductSkuInfo(erpCollectProductSkuSel);
    }

    @PostMapping("/getCollectProductSkuListInfo")
    public R<Object> getCollectProductSkuListInfo(@RequestBody ErpCollectProductSku erpCollectProductSkuSel){
        return iErpCollectProductSkuService.getCollectProductSkuListInfo(erpCollectProductSkuSel);
    }

    /**
     * 查询采集商品SKU;参考AE-商品：发布产品信息（aliexpress.postproduct.redefining.postaeproduct）列表
     */
    @PostMapping("/getCollectProductSkuList")
    public List<ErpCollectProductSku> getCollectProductSkuList(@RequestBody ErpCollectProductSku collectProductSku){
        return iErpCollectProductSkuService.queryCollectProductSkuList(collectProductSku);
    }

    /**
     *
     *
     * @param skuCode 主键
     */
    @GetMapping("/getSpecBySkuCodeNew/{skuCode}")
    public R<Object> getSpecBySkuCodeNew(@PathVariable String skuCode) {
        return R.ok(iErpCollectProductSkuService.getSpecBySkuCodeNew(skuCode));
    }

    @GetMapping("/getImageBySkuCdeNew/{skuCode}")
    public R<Object> getImageBySkuCdeNew(@PathVariable String skuCode) {
        return R.ok(iErpCollectProductSkuService.getImageBySkuCodeNew(skuCode));
    }
}
